package cn.wbnull.springbootdemo.config;

import cn.wbnull.springbootdemo.boot.SnakeWebSocketHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.*;

@Configuration
@EnableWebSocket
public class WebSocketTowConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(gameWebSocketHandler(), "/ws")    // 指定路径和处理器
                .addHandler(gameWebSocketHandler(), "/ws/133")// 指定路径和处理器
                .setAllowedOriginPatterns("*");  // 注意方法名改为setAllowedOriginPatterns

    }

    @Bean
    public WebSocketHandler gameWebSocketHandler() {
        return new SnakeWebSocketHandler();
    }
}